package liguo.application;

import android.app.Application;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;

import com.liguo.whoisthespy.R;

import io.realm.Realm;
import liguo.getCrash.CrashLog;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;


public class BaseApplication extends Application {
    private static Context context;
    private static int statusBarHeight = 0;
    public static Typeface tf;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        Realm.init(this);
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("hyyyt.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build()
        );

        AssetManager mgr=context.getAssets();//得到AssetManager
        tf= Typeface.createFromAsset(mgr, "hyyyt.ttf");//根据路径得到Typeface

        CrashLog.getInstance().init(BaseApplication.getContext(),"1043274460@qq.com","gkfbkpfltrnlbfeh",BaseApplication.getContext().getString(R.string.app_name),"2563892038@qq.com");
    }
    public static Context getContext() {
        return context;
    }
    /**
     * 获得状态栏高度
     * @return
     */
    public static int getStatusBarHeight()
    {
        if(statusBarHeight == 0){
            int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0)
            {
                try {
                    statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
                }catch (Exception e){
                    statusBarHeight = 0;
                }
            }
        }
        return statusBarHeight;
    }
}
